// 在创建应用菜单时确保有粘贴权限
const { Menu } = require("electron");

const template = [
  {
    label: "自定义菜单",
    submenu: [
      { role: "undo" },
      { role: "redo" },
      { type: "separator" },
      { role: "cut" },
      { role: "copy" },
      { role: "paste" }, // 确保有这一项
      // ...其他菜单项
    ],
  },
];

// 设置系统菜单
Menu.setApplicationMenu(Menu.buildFromTemplate(template));

// 创建右键菜单(上下文菜单)
exports.contextMenu = (win) => {
  // 监听 context-menu 事件
  win.webContents.on("context-menu", (e, params) => {
    const menu = Menu.buildFromTemplate([
      {
        label: "粘贴",
        click: () => {
          win.webContents.paste();
        },
        enabled: params.editFlags.canPaste,
      },
      // 可以根据需要添加更多菜单项，如复制、剪切等
      {
        label: "复制",
        click: () => {
          win.webContents.copy();
        },
        enabled: params.editFlags.canCopy,
      },
      {
        label: "剪切",
        click: () => {
          win.webContents.cut();
        },
        enabled: params.editFlags.canCut,
      },
    ]);
    menu.popup({ window: win });
  });
};
